# encoding:utf-8
from functools import wraps
from flask import session, flash, redirect, url_for, g


def get_current_user():
    """获取当前user"""
    if 'user' not in session:
        return None
    return session['user']


def require_admin(func):
    """Check if user is admin"""

    @wraps(func)
    def decorator(*args, **kwargs):
        if  g.user !='admin':
            flash('此操作需要管理员账户')
            return redirect(url_for('employee.login'))
        return func(*args, **kwargs)

    return decorator
